package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api( tags = "菜品相关接口")
public class DishController {
    @Autowired
    private DishService dishService;

    //json数据格式的数据才使用@RequestBody
    @PostMapping("/admin/dish")
    @ApiOperation( value="新增菜品接口")
    public Result insert(@RequestBody DishDTO dishDTO)
    {
        log.info("新增菜品：{}", dishDTO);
        dishService.insert(dishDTO);
        return Result.success();
    }


    @ApiOperation( value="菜品分页查询接口")
    @GetMapping("/admin/dish/page")
    public Result<PageResult> selectByPage(DishPageQueryDTO dishPageQueryDTO)
    {
        log.info("菜品分页查询参数；{}", dishPageQueryDTO);
        PageResult result = dishService.selectByPage(dishPageQueryDTO);
        return Result.success(result);
    }

    @ApiOperation( value="菜品停售/起售接口")
    @PostMapping("/admin/dish/status/{status}")
    public Result updateStatus(@PathVariable Integer status, Long id)
    {
        log.info("菜品停售/起售接口，参数：{},{}", status, id);
        dishService.updateStatus(status, id);
        return Result.success();
    }

    @ApiOperation( value="菜品根据分类id查询菜品")
    @GetMapping("/admin/dish/list")
    public Result selectByCategoryId(Long categoryId)
    {
        log.info("菜品根据id查询菜品，参数：{}", categoryId);
        List<DishVO> dishVO = dishService.selectByCategoryId(categoryId);
        return Result.success(dishVO);
    }

    @ApiOperation( value="菜品根据id查询菜品")
    @GetMapping("/admin/dish/{id}")
    public Result selectById(@PathVariable Long id)
    {
        log.info("菜品根据id查询菜品，参数：{}", id);
        DishVO dishVO = dishService.selectById(id);
        return Result.success(dishVO);
    }

    @ApiOperation( value="菜品修改接口")
    @PutMapping("/admin/dish")
    public Result update(@RequestBody DishDTO dishDTO)
    {
            log.info("菜品修改接口，参数：{}", dishDTO);
            dishService.update(dishDTO);
            return Result.success();
    }

    @ApiOperation( value="菜品批量删除接口")
    @DeleteMapping("/admin/dish")
    public Result delete(@RequestParam List<Long> ids)
    {
        log.info("菜品批量删除接口，参数：{}", ids);
        dishService.delete(ids);
        return Result.success();
    }
}
